package kaoshi;

public class Quest14 {
    public static void main(String[] args) {
        int [][] nums = {
                {1},
                {1,2},
                {1,2,3},
                {1,2,3,4}
        };
        System.out.println(angel(nums));
    }
    public static int angel(int [][] nums){
        int length = nums.length;
        for (int i = length-2 ; i>-1;i--){
            for (int j = 0; j < i+1; j++) {
                nums[i][j]=max(nums[i+1][j],nums[i+1][j+1])+nums[i][j];
            }
        }
        return nums[0][0];
    }

    private static int max(int a,int b) {
        return a>b?a:b;
    }
}
